package view;

import controller.MainListener;
import pojo.Book;
import pojo.User;

import javax.swing.*;
import java.awt.*;
import java.util.List;

public class MainJFrame extends JFrame{
    private JPanel panel;
    private CardLayout layout;
    private MainListener listener;
    private List<Book> bookList;
    private List<User> userList;
    private SignIn signIn;
    private String UserId;
    private String UserType;
    private User user;
    private ImageIcon image;
    public MainJFrame(){
        //标题
        this.setTitle("图书管理系统");
        this.setVisible(false);
        signIn=new SignIn(this);
        //主体
        this.setSize(900,800);
        this.setResizable(false);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        listener = new MainListener(this,bookList,userList);
//        this.setLayout(null);
        this.setLayout(new BorderLayout());
        JLabel photo1=new JLabel(new ImageIcon("src/image/photo14.png"));
        this.add(photo1,BorderLayout.NORTH);
//        jl3.setBounds(0, 0, 900, 160);
//        this.getJSPanel().setBounds(0,160,900,640);
        this.add(this.getJSPanel(),BorderLayout.CENTER);

    }
    //左右布局
    public JSplitPane getJSPanel(){
        JSplitPane panel =new JSplitPane(1,this.getLeftPanel(),this.getRightPanel());
        // 分隔条左侧的宽度为150像素
        panel.setDividerLocation(200);
        // 分隔条的宽度为1像素
        panel.setDividerSize(1);
        // 分隔条上方的高度为30像素
        //panel.setDividerLocation(30);

        return panel;
    }
    public JPanel getLeftPanel(){
        JPanel panel=new JPanel();
        panel.setLayout(new GridLayout(4,1));
        JButton jButton1=new JButton("图书分类");
        JButton jButton2=new JButton("图书查询");
        JButton jButton3=new JButton("租阅查询");
        JButton jButton4=new JButton("用户管理");
        jButton1.setFont( new Font ( "隶书" , Font.BOLD , 30));
        jButton2.setFont( new Font ( "隶书" , Font.BOLD , 30));
        jButton3.setFont( new Font ( "隶书" , Font.BOLD , 30));
        jButton4.setFont( new Font ( "隶书" , Font.BOLD , 30));
        jButton1.setBackground(Color.white);
        jButton2.setBackground(Color.white);
        jButton3.setBackground(Color.white);
        jButton4.setBackground(Color.white);
        jButton1.setForeground(new Color(196, 81, 41));
        jButton2.setForeground(new Color(196, 81, 41));
        jButton3.setForeground(new Color(196, 81, 41));
        jButton4.setForeground(new Color(196, 81, 41));
        jButton1.setFocusPainted(false);//去焦点
        jButton1.setBorderPainted(false);//去边框
        jButton2.setFocusPainted(false);//去焦点
        jButton2.setBorderPainted(false);//去边框
        jButton3.setFocusPainted(false);//去焦点
        jButton3.setBorderPainted(false);//去边框
        jButton4.setFocusPainted(false);//去焦点
        jButton4.setBorderPainted(false);//去边框


        jButton1.addActionListener(listener);
        jButton2.addActionListener(listener);
        jButton3.addActionListener(listener);
        jButton4.addActionListener(listener);
        panel.add(jButton1);
        panel.add(jButton2);
        panel.add(jButton3);
        panel.add(jButton4);

        return panel;
    }
    public JPanel getRightPanel(){
        panel = new JPanel();
        layout = new CardLayout();
        panel.setLayout(layout);
        JLabel photo2=new JLabel(new ImageIcon("src/image/photo15.png"));
        panel.add(photo2);
        return panel;
    }

    public JPanel getPanel() {
        return panel;
    }

    public CardLayout getLayout() {
        return layout;
    }

    public void setUser(User user) {
        this.user=user;
    }

    public User getUser() {
        return user;
    }

    public String getUserId() {
        return UserId;
    }

    public void setUserId(String userId) {
        UserId = userId;
    }


}
